package data.missions;

import data.Map;
import data.Player;
import data.tileables.Controllable;
import data.tileables.Melee;

public class TrainMelee extends Mission{
	private Player player;
	private boolean resourceDeducted;
	private int ticksLeft;
	public TrainMelee(Controllable c, Map m, Player p)
	{
		thisControllable = c;
		displayName = "Train Melee";
		player = p;
		resourceDeducted = false;
		ticksLeft = Melee.BUILDTIME;
	}
	public int execute()
	{
		int[] resources = player.getResources();
		if(!resourceDeducted)
		{
			if(resources[0] >= Melee.PRICE[0] && resources[1] >= Melee.PRICE[1] && resources[2] >= Melee.PRICE[2])
			{
				player.setResource(0, resources[0] - Melee.PRICE[0]);
				player.setResource(1, resources[1] - Melee.PRICE[1]);
				player.setResource(2, resources[2] - Melee.PRICE[2]);
				System.out.println("Resources deducted for " + displayName);
				System.out.println(Melee.PRICE[0] + " " + Melee.PRICE[1] + " " + Melee.PRICE[2]);
				resourceDeducted = true;
				return 0;
			}
			System.out.println(getName()+ " failed because not enough resources!");
			return 1;
		}
		else
		{
			if(ticksLeft > 0)
			{
				ticksLeft--;
				return 0;
			}
			else
			{
				player.createMelee(thisControllable.getX(), thisControllable.getY());
				return 1;
			}
		}		
	}
}
